package com.googlecode.cnasort.cc.rmi.common;

import java.io.File;
import java.io.Serializable;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.googlecode.cnasort.cc.rmi.common.data.RMIFileDir;

public class RMIFileDirImpl implements RMIFileDir, Serializable
{
    private static final long serialVersionUID = 1L;
    private String path;
    private String name;
    private long length;
    private long lastModified;

    public RMIFileDirImpl(File file)
    {
        this.path         = file.getPath();
        this.name         = file.getName();
        this.length       = file.length();
        this.lastModified = file.lastModified();
    }

    @Override
    public Path getPath()
    {
        return Paths.get( path );
    }

    @Override
    public String getName()
    {
        return name;
    }

    @Override
    public File getFile()
    {
        return new File( path );
    }

    protected long getLength()
    {
        return length;
    }

    protected long getLastModified()
    {
        return lastModified;
    }

    @Override
    public String toString() {
        return '[' + path + "][" + length + ':' + lastModified + ']';
    }

    public static String toString( RMIFileDir[] files )
    {
        StringBuilder sb = new StringBuilder();

        sb.append( '{' );

        for( RMIFileDir file : files ) {
            sb.append( file );
            sb.append( ',' );
            }

        sb.append( '}' );

        return sb.toString();
    }
}
